import request from '@/utils/request'
// 引入接口类型
import type {ResMenuListModel, MenuInfoModel} from './model/permissionModel'

// 定义枚举类型的接口地址
enum Api {
  // 获取菜单
  GetMenu = '/admin/acl/permission',
  // 给角色分配权限
  AssignPermission = '/admin/acl/permission/doAssign',
  // 给角色分配权限
  AssignAclPermission = '/admin/acl/permission/doAssignAcl',
  // 递归删除菜单
  RecursionDeleteMenu = '/admin/acl/permission/remove',
  // 新增菜单
  SaveMenu = '/admin/acl/permission/save',
  // 修改菜单
  UpdateMenu  = '/admin/acl/permission/update',
  // 根据角色获取菜单
  GetMenuByRoleId = '/admin/acl/permission/toAssign'
}

// 获取菜单的接口函数
export const getMenuApi = () => request.get<any, ResMenuListModel>(Api.GetMenu)
// 给角色分配权限
export const assignPermissionApi = (roleId: string, permissionId: string) => request.post<any, null>(Api.AssignPermission, null, {
  params: {roleId, permissionId}
})
// 给角色分配权限
// export const assignAclPermissionApi = () => request.post<any, null>(Api.AssignAclPermission)
// 递归删除菜单
export const recursionDeleteMenuApi = (id: string) => request.delete<any, null>(Api.RecursionDeleteMenu + `/${id}`)
// 新增菜单
export const saveMenuApi = (permission: MenuInfoModel) => request.post<any, null>(Api.SaveMenu, permission)
// 修改菜单
export const updateMenuApi = (permission: MenuInfoModel) => request.put<any, null>(Api.UpdateMenu, permission)
// 根据角色获取菜单
export const getMenuByRoleIdApi = (roleId: string) => request.get<any, ResMenuListModel>(Api.GetMenuByRoleId + `/${roleId}`)

// 新增/修改菜单
export const saveOrUpdateMenuApi = (permission: MenuInfoModel) => {
  if (permission.id) {
    return request.put<any, null>(Api.UpdateMenu, permission)
  } else {
    return request.post<any, null>(Api.SaveMenu, permission)
  }
}


